/*Dynamic programming . The time complex is O(n)*/
#include<iostream> 
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main()
{
    int n,a[10001],i,j,k,l;
    while(cin>>n && n!=0 )
    {
        for(i=0;i<n;i++)
          cin>>a[i];
        /* if the array is no more than 0, process it specially 
           for example: -1 0 -2
        */
        bool flag = false , flag1 = false;
        for(i=0;i<n;i++)
        {
            if(a[i]>0 )    { flag = true; break; }
            else if(a[i]==0) { flag1 = true; }
        }
        if( !flag && flag1 ) { printf("0 0 0\n");continue;} 
        
        int maxEndinghere = 0 ,maxSofar = 0;
        //double maxSofar = -0.5;
        int left = 0,right = n-1,l = 0 ,count = 0;
        for(i=0;i<n;i++)
        {
            maxEndinghere += a[i];
            if( maxEndinghere<0 )
            {
                maxEndinghere = 0;
                l = i+1;    
                count++;
            }
            if( maxSofar<maxEndinghere ) 
            {
                maxSofar = maxEndinghere;
                left = l;
                right = i;    
            }
        }//for                
        if( count==n ) cout<<0<<" "<<a[0]<<" "<<a[n-1]<<endl;
        else cout<<maxSofar<<" "<<a[left]<<" "<<a[right]<<endl;
    }//while
    
    //system("pause");
    return 0;
}
